package com.liqi.frame.comm.controller.monitor;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liqi.frame.comm.dto.LayuiTableData;
import com.liqi.frame.comm.po.UserOnline;
import com.liqi.frame.comm.service.UserOnlineService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author liqi on 2020/1/21 0021. liqiwork@qq.com
 */
@RestController
@RequestMapping("/monitor/ajax")
public class UserOnlineAjaxController {
    @Autowired
    private UserOnlineService userOnlineService;

    @ApiOperation(value="获得在线用户列表", notes = "通过用户名称获得在线用户列表", httpMethod = "GET")
    @RequestMapping({"getGroupList"})
    public LayuiTableData getGroupList(@RequestBody Map params) {
        Integer page = (Integer)params.get("page");
        Integer limit = (Integer)params.get("limit");
        String fullname = params.get("fullname")+"";

        PageHelper.startPage(page, limit);
        List<UserOnline> list = userOnlineService.getListWithFullname(fullname);
        List listResult = new ArrayList();
        Long count = 0L;
        if (list!=null){
            PageInfo pageInfo = new PageInfo(list);
            listResult = pageInfo.getList();
            count = pageInfo.getTotal();
        }
        return LayuiTableData.success(listResult, count);
    }
}
